from PyQt5.QtWidgets import QVBoxLayout, QSlider, QDialog, QLabel
from PyQt5.QtCore import  Qt

class SettingsDialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("设置")
        self.setGeometry(500, 100, 300, 150)

        # 创建布局
        self.layout = QVBoxLayout(self)

        # 透明度设置标签
        self.opacity_label = QLabel("设置背景透明度", self)
        self.layout.addWidget(self.opacity_label)

        # 创建透明度滑块
        self.opacity_slider = QSlider(Qt.Horizontal, self)
        self.opacity_slider.setRange(0, 100)
        self.opacity_slider.setValue(100)
        self.layout.addWidget(self.opacity_slider)

        # 连接信号
        self.opacity_slider.valueChanged.connect(self.change_opacity)

    def change_opacity(self, value):
        """改变父窗口透明度"""
        if self.parent():
            print(f"Changing opacity to: {value / 100}")  # Debug output
            self.parent().setWindowOpacity(value / 100)  # 转换到0.0到1.0之间